package com.anxin.act.model.web;

import com.anxin.act.model.entity.WfActApprover;
import com.anxin.act.model.service.WfActApproverService;
import com.anxin.framework.aspectj.lang.annotation.Log;
import com.anxin.framework.aspectj.lang.enums.BusinessType;
import com.anxin.framework.security.service.TokenService;
import com.anxin.framework.web.controller.BaseController;
import com.anxin.framework.web.entity.AjaxResult;
import com.anxin.framework.web.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 工作流审批人配置Controller
 *
 * @author jbs
 * @date 2020-03-18
 */
@RestController
@RequestMapping("/wf/approver")
public class WfActApproverController extends BaseController{
    @Autowired
    private WfActApproverService wfActApproverService;


    /**
     * 获取用户待选数据
     */
    @GetMapping("/userData")
    @Log(title = "获取用户待选数据", businessType = BusinessType.LIST)
    public AjaxResult userData(){
        return AjaxResult.success(wfActApproverService.getUserData());
    }


    /**
     * 获取本门待选数据
     */
    @GetMapping("/deptData")
    @Log(title = "获取本门待选数据", businessType = BusinessType.LIST)
    public AjaxResult deptData(){
        return AjaxResult.success(wfActApproverService.getDeptData());
    }


    /**
     * 获取本门待选数据
     */
    @GetMapping("/roleData")
    @Log(title = "获取本门待选数据", businessType = BusinessType.LIST)
    public AjaxResult roleData(){
        return AjaxResult.success(wfActApproverService.getRoleData());
    }

    /**
     * 表单待选数据
     */
    @GetMapping("/formFieldData/{modelId}")
    @Log(title = "表单待选数据", businessType = BusinessType.LIST)
    public AjaxResult formFieldData(@PathVariable("modelId") String modelId){
        return AjaxResult.success(wfActApproverService.getFormFieldData(modelId));
    }


    /**
     * 保存数据
     * @return
     */
    // @PreAuthorize("@ss.hasPermi('oa:contract:list')")
    @PostMapping("/save")
    @Log(title = "工作流审批人配置-保存数据", businessType = BusinessType.INSERT)
    public AjaxResult save(HttpServletRequest request){
        return wfActApproverService.save(request.getParameter("data"));
    }

    /**
     * 根据actUuid,modelId 查询数据
     * @return
     */
    @GetMapping("/findList")
    @Log(title = "根据actUuid,modelId 查询数据", businessType = BusinessType.LIST)
    public TableDataInfo<List<WfActApprover>> findList(String actUuid,String modelId){
        return getDataTable(wfActApproverService.findList(actUuid));
    }



}
